<form class="layui-form layui-box" style='padding:25px 30px 20px 0' action="__SELF__" data-auto="true" method="post">

    <div class="layui-form-item">
        <label class="layui-form-label">用户账号</label>
        <div class="layui-input-block">
            {if $vo and $vo.uname}
            <input readonly="readonly" disabled="disabled" name="uname" value='{$vo.uname|default=""}'
                   required="required" title="请输入用户名称" placeholder="请输入用户名称" class="layui-input layui-disabled">
            {else}
            <input name="uname" value='{$vo.uname|default=""}' required="required" title="请输入用户名称"
                   placeholder="请输入用户名称" class="layui-input">
            {/if}
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">邮箱号</label>
        <div class="layui-input-block col-lg-7" style="margin-left: 0">
            <input id="email" type="email" name="email" value='' pattern="^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$"  required="" title="请输入邮箱号" placeholder="请输入邮箱号" class="layui-input">
        </div>
        <div class="layui-input-block col-lg-2" style="margin-left: 0">
           <!-- <span id="get_code" class="layui-btn" onclick="settime(this)">获取验证码</span> -->
           <input class="layui-btn" type="button" id="btn" value="免费获取验证码" /> 
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">邮箱验证码</label>
        <div class="layui-input-block">
            <input type="text" name="email_code" value='' required="required" pattern="^[0-9]{6}$"  required="" title="请输入邮箱验证码" placeholder="请输入邮箱验证码" class="layui-input">
        </div>
    </div>

    <div class="hr-line-dashed"></div>

    <div class="layui-form-item text-center">
        {if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if}
        <button class="layui-btn" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>

</form>
<script type="text/javascript">
    // 发送邮箱
    $('#btn').click(function(){
        var id = "{$vo.id}";
        var email = $('#email').val();
        var me = $(this);
        var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        res = pattern.test(email);
        if(res == false){
            alert('请输入邮箱号');
            return false;
        }else{
            var url = '{:url("$classuri/get_email_code")}';
            $.post(url,{'email':email,'id':id},function(data){
                if(data.code == 400){
                    alert(data.message);
                }else{
                    alert('发送成功');
                    settime();
                }
            },'json')
        }

    });

    var countdown=60; 
    function settime() { 
        var res = setTimeout(function() { 
            settime() 
        },1000) 
        if (countdown == 0) { 
            $('#btn').removeAttr("disabled"); 
            $('#btn').val("获取验证码"); 
            countdown = 60; 
            clearInterval(res);  
        } else { 
            $('#btn').attr("disabled", true); 
            $('#btn').val("重新发送(" + countdown + ")"); 
            countdown--; 
        } 
    } 
</script>
